libxc: osdep: convert xc_map_foreign_{batch,bulk}
authorIan Campbell <ian.campbell@citrix.com>
Fri, 3 Dec 2010 09:36:47 +0000 (09:36 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 3 Dec 2010 09:36:47 +0000 (09:36 +0000)
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxc/Makefile
tools/libxc/xc_foreign_memory.c [new file with mode: 0644]
tools/libxc/xc_linux.c
tools/libxc/xc_minios.c
tools/libxc/xc_misc.c
tools/libxc/xc_netbsd.c
tools/libxc/xc_solaris.c
tools/libxc/xenctrlosdep.h

index 18524084976b7e05e564567186ad4b53cdc3a3d0..ff23f30c582ac4f73996c03aeb67674504426ae9 100644 (file)
@@ -30,6 +30,7 @@ CTRL_SRCS-y       += xc_mem_event.c
 CTRL_SRCS-y       += xc_mem_paging.c
 CTRL_SRCS-y       += xc_memshr.c
 CTRL_SRCS-y       += xc_hcall_buf.c
+CTRL_SRCS-y       += xc_foreign_memory.c
 CTRL_SRCS-y       += xtl_core.c
 CTRL_SRCS-y       += xtl_logger_stdio.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c
new file mode 100644 (file)
index 0000000..953f63b
--- /dev/null
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * xc_foreign_memory.c
+ *
+ * Functions for mapping foreign domain's memory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "xc_private.h"
+
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
+                           xen_pfn_t *arr, int num )
+{
+    return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle,
+                                                 dom, prot, arr, num);
+}
+
+void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
+                          const xen_pfn_t *arr, int *err, unsigned int num)
+{
+    return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle,
+                                                dom, prot, arr, err, num);
+}
index a0539cd0b5e48eabab933dd9e6168de540dea326..76d47918457730d327beb520f26c7e018ee6194c 100644 (file)
@@ -81,7 +81,7 @@ static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd
     return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 }
 
-static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
+static int xc_map_foreign_batch_single(int fd, uint32_t dom,
                                        xen_pfn_t *mfn, unsigned long addr)
 {
     privcmd_mmapbatch_t ioctlx;
@@ -96,21 +96,23 @@ static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
     {
         *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB;
         usleep(100);
-        rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+        rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
     }
     while ( (rc < 0) && (errno == ENOENT) );
 
     return rc;
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
+static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+                                             uint32_t dom, int prot,
+                                             xen_pfn_t *arr, int num)
 {
+    int fd = (int)h;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     int rc;
 
-    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0);
+    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
     if ( addr == MAP_FAILED )
     {
         PERROR("xc_map_foreign_batch: mmap failed");
@@ -122,7 +124,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
     ioctlx.addr = (unsigned long)addr;
     ioctlx.arr = arr;
 
-    rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+    rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
     if ( (rc < 0) && (errno == ENOENT) )
     {
         int i;
@@ -133,7 +135,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
                  XEN_DOMCTL_PFINFO_PAGEDTAB )
             {
                 unsigned long paged_addr = (unsigned long)addr + (i << PAGE_SHIFT);
-                rc = xc_map_foreign_batch_single(xch, dom, &arr[i],
+                rc = xc_map_foreign_batch_single(fd, dom, &arr[i],
                                                  paged_addr);
                 if ( rc < 0 )
                     goto out;
@@ -154,16 +156,18 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
     return addr;
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
+static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
+                                            uint32_t dom, int prot,
+                                            const xen_pfn_t *arr, int *err, unsigned int num)
 {
+    int fd = (int)h;
     privcmd_mmapbatch_v2_t ioctlx;
     void *addr;
     unsigned int i;
     int rc;
 
     addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
-                xch->fd, 0);
+                fd, 0);
     if ( addr == MAP_FAILED )
     {
         PERROR("xc_map_foreign_batch: mmap failed");
@@ -176,7 +180,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
     ioctlx.arr = arr;
     ioctlx.err = err;
 
-    rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+    rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
 
     if ( rc < 0 && errno == ENOENT )
     {
@@ -192,7 +196,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
             ioctlx.err = err + i;
             do {
                 usleep(100);
-                rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+                rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
             } while ( rc < 0 && err[i] == -ENOENT );
         }
     }
@@ -216,7 +220,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
             ioctlx.addr = (unsigned long)addr;
             ioctlx.arr = pfn;
 
-            rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+            rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
 
             rc = rc < 0 ? -errno : 0;
 
@@ -236,7 +240,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
                         err[i] = rc ?: -EINVAL;
                         continue;
                     }
-                    rc = xc_map_foreign_batch_single(xch, dom, pfn + i,
+                    rc = xc_map_foreign_batch_single(fd, dom, pfn + i,
                         (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
                     if ( rc < 0 )
                     {
@@ -328,6 +332,9 @@ static struct xc_osdep_ops linux_privcmd_ops = {
 
     .u.privcmd = {
         .hypercall = &linux_privcmd_hypercall,
+
+        .map_foreign_batch = &linux_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &linux_privcmd_map_foreign_bulk,
     },
 };
 
index 076605a743a37755f3eedf1e737b82d40a5fdef9..624889d19387aaecff7e80938d6cee928adf38db 100644 (file)
@@ -93,8 +93,9 @@ static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
     return call.result;
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
+static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
+                                             uint32_t dom, int prot,
+                                             const xen_pfn_t *arr, int *err, unsigned int num)
 {
     unsigned long pt_prot = 0;
 #ifdef __ia64__
@@ -108,8 +109,9 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
+static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  xc_osdep_handle h,
+                                              uint32_t dom, int prot,
+                                              xen_pfn_t *arr, int num)
 {
     unsigned long pt_prot = 0;
     int err[num];
@@ -185,6 +187,9 @@ static struct xc_osdep_ops minios_privcmd_ops = {
 
     .u.privcmd = {
         .hypercall = &minios_privcmd_hypercall,
+
+        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
     },
 };
 
index 944646e28c0cb9d502d18d4e5e0c9ca9cbf9eb18..23398f773bb11257234ea4e4b3c490325b604cdd 100644 (file)
@@ -513,12 +513,9 @@ int xc_hvm_set_mem_type(
 
 
 /* stub for all not yet converted OSes */
-void *
-#ifdef __GNUC__
-__attribute__((__weak__))
-#endif
-xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                    const xen_pfn_t *arr, int *err, unsigned int num)
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+                                 uint32_t dom, int prot,
+                                 const xen_pfn_t *arr, int *err, unsigned int num)
 {
     xen_pfn_t *pfn;
     unsigned int i;
index 3c3b90d178fcccfa67eca768aee7ea3af6a5a549..671ae2c3a67fbbdb6889fa108fd42d9f8f8956a4 100644 (file)
@@ -79,9 +79,11 @@ static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
         return hypercall->retval;
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
+static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+                                              uint32_t dom, int prot,
+                                              xen_pfn_t *arr, int num)
 {
+    int fd = (int)h;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
@@ -94,7 +96,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
     ioctlx.dom=dom;
     ioctlx.addr=(unsigned long)addr;
     ioctlx.arr=arr;
-    if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+    if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
     {
         int saved_errno = errno;
         PERROR("xc_map_foreign_batch: ioctl failed");
@@ -178,6 +180,9 @@ static struct xc_osdep_ops netbsd_privcmd_ops = {
 
     .u.privcmd = {
         .hypercall = &netbsd_privcmd_hypercall;
+
+        .map_foreign_batch = &netbsd_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &xc_map_foreign_bulk_compat,
     },
 };
 
index cdcc2222c42832f19de9c6508c85d2263f68aeed..8152868e7c97737122d0064e635ffc9037b0eb7c 100644 (file)
@@ -74,12 +74,14 @@ static int solaris_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privc
     return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 }
 
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
+static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+                                               uint32_t dom, int prot,
+                                               xen_pfn_t *arr, int num)
 {
+    int fd = (int)h;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
-    addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xch->fd, 0);
+    addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0);
     if ( addr == MAP_FAILED )
         return NULL;
 
@@ -87,7 +89,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
     ioctlx.dom=dom;
     ioctlx.addr=(unsigned long)addr;
     ioctlx.arr=arr;
-    if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+    if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
     {
         int saved_errno = errno;
         PERROR("XXXXXXXX");
@@ -168,6 +170,9 @@ static struct xc_osdep_ops solaris_privcmd_ops = {
 
     .u.privcmd = {
         .hypercall = &solaris_privcmd_hypercall;
+
+        .map_foreign_batch = &solaris_privcmd_map_foreign_batch,
+        .map_foreign_bulk = &xc_map_foreign_bulk_compat,
     },
 };
 
index 59928fb7b7ac7862580a2981fd656b53a09e5dc9..204b9e87e96b16971622759e3c8a71e377fbce58 100644 (file)
@@ -63,6 +63,11 @@ struct xc_osdep_ops
     union {
         struct {
             int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall);
+
+            void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+                                       xen_pfn_t *arr, int num);
+            void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+                                      const xen_pfn_t *arr, int *err, unsigned int num);
         } privcmd;
     } u;
 };
@@ -83,6 +88,11 @@ typedef struct xc_osdep_info xc_osdep_info_t;
 /* All backends, including the builtin backend, must supply this structure. */
 extern xc_osdep_info_t xc_osdep_info;
 
+/* Stub for not yet converted OSes */
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+                                 uint32_t dom, int prot,
+                                 const xen_pfn_t *arr, int *err, unsigned int num);
+
 #endif
 
 /*